package naga.x.platform2.channel.s399.support;

import java.util.Arrays;
import java.util.Collections;
import java.util.Set;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import naga.x.platform2.App;
import naga.x.platform2.app.Channel;

@Configuration
@EnableAutoConfiguration
@ConfigurationProperties(locations = "classpath:4399.properties")
public class S399Config implements InitializingBean {

	private String clientUrl;
	private String callbackKey;
	private String gameId;
	private int loginTimeout; // 登录超时时间（秒）
	private int payTimeout; // 支付超时时间（秒）
	private String[] ipWhitelist;
	private Set<String> userWhitelist; // 白名单账号只能在测试服充值
	private boolean debug;

	public String getClientUrl() {
		return clientUrl;
	}

	public void setClientUrl(String clientUrl) {
		this.clientUrl = clientUrl;
	}

	public String getCallbackKey() {
		return callbackKey;
	}

	public void setCallbackKey(String callbackKey) {
		this.callbackKey = callbackKey;
	}

	public String getGameId() {
		return gameId;
	}

	public void setGameId(String gameId) {
		this.gameId = gameId;
	}
	
	public int getLoginTimeout() {
		return loginTimeout;
	}

	public void setLoginTimeout(int loginTimeout) {
		this.loginTimeout = loginTimeout;
	}

	public int getPayTimeout() {
		return payTimeout;
	}

	public void setPayTimeout(int payTimeout) {
		this.payTimeout = payTimeout;
	}

	public String[] getIpWhitelist() {
		return ipWhitelist;
	}

	public void setIpWhitelist(String[] ipWhitelist) {
		this.ipWhitelist = ipWhitelist;
	}
	
	public Set<String> getUserWhitelist() {
		return userWhitelist;
	}

	public void setUserWhitelist(Set<String> userWhitelist) {
		this.userWhitelist = userWhitelist;
	}
	
	public boolean isDebug() {
		return debug;
	}

	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	@Override
	public String toString() {
		return "[clientUrl=" + clientUrl + ", callbackKey=" + callbackKey + ", gameId=" + gameId
				+ ", loginTimeout=" + loginTimeout + ", payTimeout=" + payTimeout + ", ipWhitelist="
				+ Arrays.toString(ipWhitelist) + ", userWhitelist=" + userWhitelist + ", debug=" + debug + "]";
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		if (userWhitelist == null) {
			userWhitelist = Collections.emptySet();
		}
		Channel.S399.debug = debug;
		App.LOG.info("[4399 CONFIG LOADED]{}", this);
	}

}
